package particlesystem.effects {
	import particlesystem.core.ParticleData;
	import particlesystem.utils.Range;

	public class GroundEffect implements IEffect {

		private var ground : Range;
		private var decay : Number;

		public function GroundEffect(background : Number, foreground : Number, decay : Number) {
			this.decay = decay;
			ground = new Range(background, foreground);
		}

		public function reset(particleData : ParticleData) : void {
			particleData.ground = ground.range;
		}

		public function update(particleData : ParticleData) : void {
			if(particleData.y > particleData.ground) {
				particleData.xSpeed *= decay;
				particleData.ySpeed *= decay;
				particleData.ySpeed = -particleData.ySpeed;
				
				particleData.y = particleData.ground - (particleData.y - particleData.ground);
			}
		}
	}
}
